import { mat4, vec3 } from 'gl-matrix';


export function cartesianToEuler() {

}

/**
 *欧拉角坐标系转换为笛卡尔坐标系
 * @export 
 * const result = eulerToCartesian([-10.8, -11.8, 0, 0, 0, 0])
 * @param {*} coord [x, y, z, r, p, y]
 * @return {*}  coord [x, y, z]
 */
export function eulerToCartesian(coord) {
  const [x, y, z, xAngle, yAngle, zAngle] = coord;
  const width = 1; // 假设物体的宽度为 1
  const height = 1; // 假设物体的高度为 1
  const depth = 1; // 假设物体的深度为 1

  // 创建旋转矩阵
  const rotationMatrix = mat4.create();
  mat4.fromXRotation(rotationMatrix, x); // 根据 x 角度旋转
  mat4.rotateY(rotationMatrix, rotationMatrix, y); // 根据 y 角度旋转
  mat4.rotateZ(rotationMatrix, rotationMatrix, z); // 根据 z 角度旋转
  // 单位向量
  const directionVector = vec3.fromValues(1, 0, 0);
  // 将单位向量旋转到物体的方向
  const rotatedDirection = vec3.transformMat4(vec3.create(), directionVector, rotationMatrix);

  // 计算物体的笛卡尔坐标
  const cartesianX = rotatedDirection[0] * width + xAngle;
  const cartesianY = rotatedDirection[1] * height + yAngle;
  const cartesianZ = rotatedDirection[2] * depth + zAngle;
  return [cartesianX, cartesianY, cartesianZ]
}




